<?php
namespace App\DBs;

use Illuminate\Support\Facades\DB;

class StampDB extends BaseDB
{
    /**
     * 用户标识
     */

    public $tStamp = 'u_stamp';

    public function __construct()
    {
    }

    //获取
    public function getOneByStamp($stamp)
    {
        $one = DB::table($this->tStamp)->where('stamp',$stamp)->first();
        return $one ? $one->id : 0;
    }

    //新增
    public function setAdd($stamp)
    {
        //开启事务
        DB::beginTransaction();
        try {
            $lastId = DB::table($this->tStamp)->insertGetId([
                'stamp'=>$stamp, 'created_at'=>time(),
            ]);
            //提交事务
            DB::commit();
            return array('code'=>'0', 'msg'=>'操作成功', 'data'=>$lastId);
        } catch (\Exception $e) {
            //事务回滚
            DB::rollBack();
            return array('code'=>'-1', 'msg'=>'操作失败：'.$e);
        }
    }
}